/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-08-14
 * Time: 17:26
 */
public class OperDemo {
    //一：运算符

    //1.在java中bool类型只能为true 或 false，否则报错

    //2.在JVM的规范中没有规范bool类型的大小，遇见选择题迫不得已时选这个

    public static void main1(String[] args) {
        //System.out.println("hello");
        //short s = 10;//2  16   -2^15 -- 2^15 - 1
        boolean flg = true;
        System.out.println(flg);
    }
    //3.引用类型 - String 类 接口 枚举

    // + 号代表字符串拼接
    public static void main2(String[] args) {
        String str = "hello";
        System.out.println(str);

        //注意问题:拼接顺序
        System.out.println("hello" + "world");
        System.out.println("hello" + 10 + 20);
        System.out.println(10 + 20 + "hello");
        System.out.println("hello" + (10 + 20));
        System.out.println(10 + "" + 20 + "hello");

        //a = 10, b = 20
        System.out.println("a="+10+", b="+20);
        String s1 = "bit";
        String s2 = "\\bit\\";
        String s3 = "\"bit\"";
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
    //4.常量： 1.字面值常量 2.final修饰的变量 常量
    public static void main3(String[] args) {
        int a1 = 10;
        int a2 = 20;
        //final int a = 10;//报错
        int a = 99;
        {
            a = 99;
        }
        System.out.println(a);
    }

    public static void main4(String[] args) {
        int a = 10;
        long b = a;
        System.out.println(b);
        long l = 1111111111112112L;
        //int c = l;
    }

    public static void main5(String[] args) {
        /*int a = 10;
        boolean b = a;

        boolean c = true;
        int d = (int)c;*/
        byte a = 1;//-128  127
        byte b = 2;
        byte c = (byte)(a+b);//直接+会发生整型提升，放不下
        System.out.println(c);

        //为什么不报错？ 1和2都是常量，在编译时就已经被编译为3
        byte c2 = 1+2;//3
        System.out.println(c2);

        long i1 = 10;
        long l1 = 20;
        int l2 = (int)(i1+l1);
    }

    public static void main6(String[] args) {
        int num = 10;
        String ret = String.valueOf(num);
        System.out.println(ret);

        String ret2 = num+"";
        System.out.println(ret2);
    }

    //类型包装类 - int-> Integer || char -> Character
    //其余的都是首字符大写
    public static void main7(String[] args) {
        String str = "123";
        int ret = Integer.valueOf(str);
        System.out.println(ret);
    }


    //二：运算符

    //1.程序出现异常后即停止运行
    public static void main8(String[] args) {
        int a = 1;
        int b = 2;//0
        System.out.println(a/b);
        System.out.println("hello");

        System.out.println(10%3);//1
        System.out.println(-10%3);//-1
        System.out.println(10%-3);//1
        System.out.println(-10%-3);//-1
    }

    //2.复合运算符 - 自动强制类型转换
    public static void main9(String[] args) {
        int a = 10;
        a+=1;
        System.out.println(a);

        short s = 10;
        //s = (short)(s+9);
        s += 9;//自动强制类型转换
        System.out.println(s);
    }

    public static void main10(String[] args) {
        int a = 10;
        int i1 = a++;//先使用，后++
        System.out.println(a);
        System.out.println(i1);

        int c = 10;
        int i2 = ++c;//先++， 再使用
        System.out.println(c);
        System.out.println(i2);
    }

    //3.关系运算符的返回值只能是一个bool值

    //4.所以if(布尔表达式）跟C语言不同
    //[表达式1 && 表达式2】 这两个表达式全是bool表达式
    //若表达式1为假则不执行2 || 也是一样
    public static void main11(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(a == b);//false
        System.out.println(a != b);//true
        System.out.println(a < b);//true
        System.out.println(a > b);//flase
        System.out.println(a <= b);//ture
        System.out.println(a >= b);//flase
    }

    public static void main12(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        System.out.println(a < b && b < c);
    }

    public static void main13(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(!(a < b));
    }

    public static void main14(String[] args) {
        System.out.println(10 > 20 && 10 / 0 == 0); // 打印 false
        System.out.println(10 < 20 || 10 / 0 == 0); // 打印 true
    }

    //5.按位异或 相同-0 不同-1

    //6.无符号右移 >>> 不管符号位是啥：左边统一补0
    public static void main(String[] args) {
        System.out.println(-11 <<  1);
        System.out.println(-11 >>> 2);
    }
}












